package com.ruoyi.web.controller.system;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.BPicture_af;
import com.ruoyi.system.service.IBPicture_afService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 电子图片Controller
 *
 * @author guangpipi
 * @date 2023-09-21
 */
@RestController
@RequestMapping("/system/epicture")
public class BPicture_afController extends BaseController
{
    @Autowired
    private IBPicture_afService bEPictureService;

    /**
     * 查询电子图片列表
     */
//    //@PreAuthorize("@ss.hasPermi('system:picture:list')")
    @GetMapping("/list")
    public TableDataInfo list(BPicture_af bEPicture)
    {
//        startPage();
        PageHelper.orderBy("picName");
        List<BPicture_af> list = bEPictureService.selectBEPictureList(bEPicture);
        return getDataTable(list);
    }

    /**
     * 导出电子图片列表
     */
    //@PreAuthorize("@ss.hasPermi('system:picture:export')")
    @Log(title = "电子图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BPicture_af bEPicture)
    {
        List<BPicture_af> list = bEPictureService.selectBEPictureList(bEPicture);
        ExcelUtil<BPicture_af> util = new ExcelUtil<BPicture_af>(BPicture_af.class);
        util.exportExcel(response, list, "电子图片数据");
    }

    /**
     * 获取二进制文件
     */
    @PostMapping("/getPic")
    public ResponseEntity<byte[]> getPic(@RequestBody BPicture_af bePicture)
    {
        return bEPictureService.getPic(bePicture.getId());
    }

    /**
     * 下载二进制文件
     */
    @PostMapping("/downloadPic")
    public ResponseEntity<byte[]> downloadPic(@RequestBody BPicture_af bePicture)
    {
        return bEPictureService.downloadPic(bePicture.getId());
    }


    /**
     * 获取电子图片详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:picture:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(bEPictureService.selectBEPictureById(id));
    }

    /**
     * 新增电子图片
     */
    //@PreAuthorize("@ss.hasPermi('system:picture:add')")
    @Log(title = "电子图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BPicture_af bEPicture)
    {
        return toAjax(bEPictureService.insertBEPicture(bEPicture));
    }

    /**
     * 修改电子图片
     */
    //@PreAuthorize("@ss.hasPermi('system:picture:edit')")
    @Log(title = "电子图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BPicture_af bEPicture)
    {
        return toAjax(bEPictureService.updateBEPicture(bEPicture));
    }

    /**
     * 获取文件类型
     */
    @GetMapping("getpictype/{id}")
    public String getpictype(@PathVariable String id){
        return bEPictureService.getpictype(id);
    }

    /**
     * 预览图片
     */
    @GetMapping("getFile/{id}")
    public ResponseEntity<byte[]> getFile(@PathVariable String id){
        return bEPictureService.getFile(id);
    }

    /**
     *  批量下载
     */
    @GetMapping("downloadMore/{ids}")
    public ResponseEntity<byte[]> downloadMore(@PathVariable String[] ids){
        return bEPictureService.downloadMore(ids);
    }

    /**
     * 删除电子图片
     */
    //@PreAuthorize("@ss.hasPermi('system:picture:remove')")
    @Log(title = "电子图片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bEPictureService.deleteBEPictureByIds(ids));
    }
}
